package com.netease.nie.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.netease.nie.constants.CustomGoodsConstants;
import com.netease.nie.mapper.OrdersMapper;
import com.netease.nie.model.Orders;

@Repository
public class OrdersDao {

	@Resource
	private OrdersMapper orderMapper;
	
	public Long insertOrder(Orders orders) throws Exception {
		orderMapper.insertOrder(orders);
		return orders.getId();
	}
	
	public List<Orders> listLastThreeMonthsOrderByUserId(long userId, int pageIndex, int pageSize,
			long currentTime, long threeMonthAgo) {
		return orderMapper.listLastThreeMonthsOrderByUserId(userId, pageIndex, pageSize, 
		currentTime, threeMonthAgo);
	}
	
	/**
	 * 根据userId获取个人兑换商品的数目
	 * @param userId
	 * @return
	 */
	public int getExchangeCountByUserId(long userId) {
		return orderMapper.getExchangeCountByUserId(userId);
	}
	
	public Orders getOrderByUserIdGoodsId(long userId, int goodsId, int exchangeCodeId) {
		return orderMapper.getOrderByUserIdGoodsId(userId, goodsId, exchangeCodeId);
	}
	
	public Orders getOrderByOrderIdAndUserId(long orderId, long userId) {
		return orderMapper.getOrderByOrderIdAndUserId(orderId, userId);
	}
	
	public List<Orders> queryOrdersByUserIdAndCustomGoodsCode(long userId, CustomGoodsConstants customGoodsConstants, int pageIndex, int pageSize) {
		List<Orders> orderList = null;
		if (CustomGoodsConstants.DRAW_LOTTERY == customGoodsConstants)
			orderList = orderMapper.queryDrawLotteryNormalGoodsOrdersByUserId(userId, pageIndex, pageSize);
		else if (CustomGoodsConstants.ROB == customGoodsConstants)
			orderList = orderMapper.queryRobGoodsOrdersByUserId(userId, pageIndex, pageSize);
		return orderList;
	}
}
